package com.kira.scaffoldmvc.Config;

import com.kira.scaffoldmvc.Interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

//配置我们的拦截器
@Configuration
public class WebConfig implements WebMvcConfigurer {

//这个是在配置类里面来注册我们的拦截器
//    @Autowired
//    private LoginInterceptor loginInterceptor;
//    @Override
//    public void addInterceptors(InterceptorRegistry registry) {
//
//        registry.addInterceptor(loginInterceptor).order(1)
//                .excludePathPatterns("/xxxx/xxxx","/xxxx/xxxx")//配置放行路径
//                .addPathPatterns("/**");//拦截路径，/**拦截所有
//
//
//    }

    @Override
    public void addCorsMappings(CorsRegistry registry) {


        registry.addMapping("/**")
                .allowedOriginPatterns("*") // 允许所有源
                .allowedMethods("*") // 允许所有HTTP方法
                .allowedHeaders("*") // 允许所有请求头
                .allowedOrigins()
                .allowCredentials(true) // 允许携带凭证
                .maxAge(3600L); // 预检请求结果缓存 3600秒
    }

}
